<?php

class SignupForm extends CFormModel {
    //!PENDING: дополнить поля правила

    public $email;
    public $password;
    public $cpassword;
    public $first_name;
    public $last_name;
    public $nickname;
    public $home_page_url;
    public $verifyCode;


    public function rules() {
        return array(
            array('email, password, cpassword, first_name, last_name, nickname', 'required'),
            array('nickname','length','max'=>64),
            array('email','length','max'=>64),
            array('email', 'email'),
            array('email', 'unique', 'className'=>'User'),
            array('password','length','min'=>8, 'max'=>20),
            array('password', 'compare', 'compareAttribute'=>'cpassword', 'on'=>'signup'),
            array('first_name','length','max'=>64),
            array('last_name','length','max'=>64),
            array('home_page_url','length','max'=>255),
            array('home_page_url','url'),
            array('verifyCode', 'captcha', 'allowEmpty'=>false),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'email'=>'Email',
            'password'=>'Password',
            'cpassword'=>'Confirm password',
            'first_name'=>'First Name',
            'last_name'=>'Last Name',
            'nickname'=>'Nickname',
            'home_page_url'=>'Web Page',
            'verifyCode'=>'Verification Code',
        );
    }

    /**
     * @return array attributes that can be massively assigned
     */
    public function safeAttributes() {
        return array(
            'email',
            'password',
            'cpassword',
            'first_name',
            'last_name',
            'nickname',
            'home_page_url',
            'verifyCode',
        );
    }

    public function save(){
        if(parent::validate()){
            Yii::app()->session[__CLASS__] = $this->getAttributes();
            return true;
        }
        return false;
    }

}